//
//  FirstViewController.m
//  RACOCProject
//
//  Created by tianchao wu on 2017/7/13.
//  Copyright © 2017年 tianchao wu. All rights reserved.
//

#import "FirstViewController.h"
#import "TwoViewController.h"
#import "ReactiveObjC.h"

@interface FirstViewController ()

@end

@implementation FirstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:@"跳转第二个控制器" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    button.frame = CGRectMake(0, 0, 200, 32);
    button.center = self.view.center;
    [self.view addSubview:button];
    [button addTarget:self action:@selector(clickAction:) forControlEvents:UIControlEventTouchUpInside];
    self.view.backgroundColor = [UIColor whiteColor];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

//步骤三：在第一个控制器中，监听跳转按钮，给第二个控制器的代理信号赋值，并且监听
- (void)clickAction:(UIButton *)sender
{
    // 创建第二个控制器
    TwoViewController *twoVC = [[TwoViewController alloc] init];
    
    //设置代理信号
    twoVC.delegateSignal = [RACSubject subject];
    
    // 订阅代理信号
    [twoVC.delegateSignal subscribeNext:^(id  _Nullable x) {
        NSLog(@"点击了通知按钮");
    }];
    
    // 跳转到第二个控制器
    [self presentViewController:twoVC animated:YES completion:nil];
}

@end
